<template>
  <view class="news_container">
    <customNavBar title="新闻" />

    <uni-list>
      <uni-list-item
        v-for="item in newList"
        :key="item._id"
        :title="item.author"
        :note="item.title"
        showArrow
        :thumb="item.picurl"
        thumb-size="lg"
        :rightText="formatTime(item.publish_date)"
        @tap="gotoDetail(item._id)"
      />
    </uni-list>
  </view>
</template>
<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { getWallNewsListAPI } from "@/apis/apis.js";
// 引入我们时间处理函数
import { formatTime } from "@/utils/date.js";
// 引入我们的自定义导航栏组件
import customNavBar from "../../components/customNavBar/customNavBar.vue";

const newList = ref([]);

const getWallNewsListFn = async () => {
  const res = await getWallNewsListAPI({
    select: true,
  });
  // console.log(res.data);
  newList.value = res.data;
};

const gotoDetail = (id) => {
  // console.log(id);
  uni.navigateTo({
    url: "/pages/noticeDetail/index?id=" + id,
  });
};
onLoad(async () => {
  uni.showLoading({
    title: "加载中...",
  });
  await getWallNewsListFn();
  uni.hideLoading();
});
</script>
<style lang="scss" scoped></style>
